from enum import Enum

from django.core.validators import RegexValidator
from django.db import models


class Sex_Choice(Enum):
    """
    (1) 猫的性别类
    """
    male = "雌性"
    female = "雄性"


class State_Choice(Enum):
    """
    猫的出售状态
    """
    NotState = "未出售"
    YesState = "已出售"


class varieties(models.Model):
    Cat_varieties = models.CharField(max_length=20, help_text="请输入猫的种类", primary_key=True)

    def __str__(self):
        return self.Cat_varieties.__str__()

    class Meta:
        db_table = "Cat_varieties"
        verbose_name = "种类信息表"
        verbose_name_plural = verbose_name


class CatModels(models.Model):
    Cat_Sex = models.CharField(max_length=20, choices=[(tag.value, tag.name) for tag in Sex_Choice], help_text="请输入猫性别")  # 猫性别
    Cat_varieties = models.ForeignKey(varieties, on_delete=models.CASCADE, help_text="请选择猫的种类")
    Cat_colour = models.CharField(max_length=20, help_text="请输入猫的颜色")
    Cat_state = models.CharField(max_length=20, choices=[(tag.value, tag.name) for tag in State_Choice], default=State_Choice.NotState)
    Cat_Create_time = models.DateTimeField(auto_created=True, help_text="引入时间")
    Cat_Price = models.DecimalField(max_digits=10, decimal_places=2, help_text="请输入价格", default=0.00)
    # 后台输入和add 记录时都可为空
    phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$',
                                 message="输入手机号信息有误，请重新输入")
    phone_number = models.CharField(validators=[phone_regex], max_length=17, blank=True, null=True,
                                    help_text="请输入买家的手机号信息")
    Cat_transaction_time = models.DateTimeField(null=True, help_text="交易时间")

    class Meta:
        db_table = "Cat"
        verbose_name = "猫信息管理"
        verbose_name_plural = verbose_name
